package com.ygqh.baby.service.impl;
import java.util.Date;
import java.util.List;

import com.ygqh.baby.ao.Message;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminSupplierFrame;
import  com.ygqh.baby.mapper.AdminSupplierFrameMapper;
import  com.ygqh.baby.service.AdminSupplierFrameService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminSupplierFrameExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminSupplierFrameServiceImpl implements AdminSupplierFrameService{
	
	@Autowired
	private AdminSupplierFrameMapper adminSupplierFrameMapper;
	
	@Override
	public List<AdminSupplierFrame> find() {
		AdminSupplierFrameExample example = new AdminSupplierFrameExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplierFrameMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminSupplierFrameExample example = new AdminSupplierFrameExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplierFrameMapper.countByExample(example);
	}

	@Override
	public AdminSupplierFrame findById(Long id) {
		return adminSupplierFrameMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminSupplierFrame adminSupplierFrame) {
		return adminSupplierFrameMapper.insertSelective(adminSupplierFrame);
	}

	@Override
	public int update(AdminSupplierFrame adminSupplierFrame) {
		AdminSupplierFrameExample example=new AdminSupplierFrameExample();
		example.createCriteria().andIdEqualTo(adminSupplierFrame.getId());
		return adminSupplierFrameMapper.updateByExampleSelective(adminSupplierFrame,example);
	}

	@Override
	public ResultSet<AdminSupplierFrame> search(QueryInfo queryInfo,String q) {
		List<AdminSupplierFrame>  list =  adminSupplierFrameMapper.selectSuper(queryInfo, q);
		int count = adminSupplierFrameMapper.countSuper(q);
		ResultSet<AdminSupplierFrame> resultSet = new ResultSet<AdminSupplierFrame>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminSupplierFrameExample example = new AdminSupplierFrameExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminSupplierFrame record = new AdminSupplierFrame();
		record.setStatus(DataStatus.Delete);

		return adminSupplierFrameMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminSupplierFrame adminSupplierFrame) {
		int r = 0;
		if(adminSupplierFrame.getId() != null) {
			r = this.update(adminSupplierFrame);
		}else {
			r = this.save(adminSupplierFrame);
		}
		return r;
	}

	@Override
	public AdminSupplierFrame findDetailById(Long id) {
		return adminSupplierFrameMapper.findDetailById(id);
		
	}

	@Override
	public Message deleteSoft(Long id, String operator) {
		AdminSupplierFrame frame=new AdminSupplierFrame();		
		frame.setUpdateBy(operator);
		frame.setUpdateTime(new Date());
		frame.setStatus(DataStatus.Delete);
		AdminSupplierFrameExample example=new AdminSupplierFrameExample();
		example.createCriteria().andIdEqualTo(id);
		adminSupplierFrameMapper.updateByExampleSelective(frame, example);
		
		return Message.success(null);
	}

	@Override
	public Boolean findDetailById(Long id, String frameCode) {
		return adminSupplierFrameMapper.countFrame(id,frameCode)>0?true:false;
	}

	@Override
	public List<AdminSupplierFrame> findFrameCode(Long supplierId) {
		return adminSupplierFrameMapper.selectFrameCode(supplierId);
	}
	

}

